﻿//-----------------------------------------------------------------------
// <copyright file="ServiceHost.cs" company="CodePlex">
//     Copyright (c) Doug Holland, CodePlex. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace CodePlex.Diagnostics.Services
{
    using System;
    using System.ServiceModel;

    /// <summary>
    /// Provides a host for services.
    /// </summary>
    /// <typeparam name="T">The type of service to be hosted.</typeparam>
    public sealed class ServiceHost<T> : ServiceHost
    {
        #region public ServiceHost() : base(typeof(T))

        /// <summary>
        /// Initializes a new instance of the <see cref="T:CodePlex.Diagnostics.Services.ServiceHost`1"/> class.
        /// </summary>
        public ServiceHost() : base(typeof(T))
        {
        }

        #endregion

        #region public ServiceHost(T singleton, params Uri[] baseAddresses) : base(singleton, baseAddresses)

        /// <summary>
        /// Initializes a new instance of the <see cref="T:CodePlex.Diagnostics.Services.ServiceHost`1"/> class with the instance of the service and its base addresses specified.
        /// </summary>
        /// <param name="singleton">The instance of the hosted service.</param>
        /// <param name="baseAddresses">An System.Array of type System.Uri that contains the base addresses for the hosted service.</param>
        public ServiceHost(T singleton, params Uri[] baseAddresses) : base(singleton, baseAddresses)
        {
        }

        #endregion

        #region public T Singleton

        /// <summary>
        /// Gets the singleton instance of the hosted service.
        /// </summary>
        /// <value>The hosted service object.</value>
        public T Singleton 
        {
            get
            {
                if (SingletonInstance == null)
                {
                    return default(T);
                }

                return (T) SingletonInstance;
            }
        }

        #endregion
    }
}
